﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using GrupyzServices.BdAccess;
using GrupyzServices.MailTools;
using GrupyzServices.Reports;
using DAL;

namespace webServices
{
    /// <summary>
    /// Summary description for Processos
    /// </summary>
    [WebService(Namespace = "http://descontoemgrupo.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Processos : System.Web.Services.WebService
    {

        [WebMethod(EnableSession=false)]
        public void DealConcluido(GrupyzServices.BdAccess.FinalOrderViewModel fo)
        {
            using (GrupyzEntities _entity = new GrupyzEntities())
            {
                OrderRepository or = new OrderRepository();
                DAL.Order order = or.GetOrderById(fo.OrderId);

                DoCapture capture = new DoCapture();
                string result = capture.DoCaptureCode(fo.IdPaypal, "Complete", order.Total.ToString(), "", "");
                if (result == "Success")
                {
                    //Enviar email
                    Mail.SendMailCompra(order.Email, fo);
                    order.Pendente = false;
                    order.Concluido = true;
                    _entity.Order.Attach(order);
                    _entity.SaveChanges();
                }
            }
        }

        [WebMethod(EnableSession = false)]
        public void DealPorConcluir(FinalOrderViewModel fo)
        {
            Mail.SendMailCompra(fo.Email,fo);
            GrupyzEntities _entity = new GrupyzEntities();
            OrderRepository or = new OrderRepository();
            DAL.Order order = or.GetOrderById(fo.OrderId);
            order.Pendente = false;
            order.Concluido = true;
            _entity.SaveChanges();
        }

    }
}
